#!/usr/bin/python
# -*- coding: utf-8 -*-


def rectangle_channel(b, z, h, h1, u):
    # result = {'b': b, 'z': z, 'h': h, 'h1': h1, 'u': u}
    result = {}

    # 求垂线平均流速
    if z / h <= 0.5:
        a1 = -1.17 * z / h - 0.4282
        b1 = 1.5261 * z / h + 0.4106
        c1 = -0.4168 * z / h + 0.9211
    elif 0.5 < z / h <= 2.5:
        a1 = 0.1804 * z / h - 0.9085
        b1 = -0.1704 * z / h + 1.0781
        c1 = 0.0141 * z / h + 0.7556
    else:
        raise Warning('Z/H不能大于2.5')

    result['a'] = a1
    result['b'] = b1
    result['c'] = c1

    kv = a1 * (h1 / h) ** 2 + b1 * h1 / h + c1
    v1 = u / kv

    result['垂线流速系数 Kv'] = kv
    result['垂线流速 V'] = v1

    # 垂线佛汝德数
    fr = v1 / (9.8 * h) ** 0.5
    result['佛汝德数 Fr'] = fr

    # 求断面平均流速
    xm = (fr / (2 * z / b) ** 0.125) * (b / h) ** 2
    m = 5.0e-5 * xm * xm - 0.0014 * xm + 0.1317

    xn = (fr / (2 * z / b) ** 0.125) ** 0.1
    n = 5.736 * xn * xn - 10.487 * xn + 5.8727

    ku = n * (2 * z / b) ** m
    u1 = v1 / ku

    result['m'] = m
    result['n'] = n
    result['断面流速系数 Ku'] = ku
    result['断面流速 U'] = u1

    a = b * h
    q = u1 * a
    result['断面面积 A'] = a
    result['断面流量 Q'] = q


    return result
